# coding:utf-8
import re


class ReDemo:
    def _test_findall(self):
        """
        rd = ReDemo()
        rd._test_findall()
        """
        # 普通字符匹配自身
        data = 'sh_python2'
        print(re.findall('py', data))

    def _test_dot(self):
        """
        rd = ReDemo()
        rd._test_dot()
        """
        data = 'a\nb'
        # dotall模式的两种形式
        print(re.findall('a.*b', data, re.DOTALL))
        print(re.findall('a.*b', data, re.S))

    def _test_escape_character(self):
        """
        rd = ReDemo()
        rd._test_escape_character()
        """
        # 转义字符的用法
        data = 'dsfa|bdsfdsf'
        print(re.findall('a\|b', data))

    def _test_middle_brackets(self):
        """
        rd = ReDemo()
        rd._test_middle_brackets()
        """
        # []
        data = 'abc-adc'
        print(re.findall('a[bd]c', data))
        print(re.findall('abc|adc', data))

    def _test_add(self):
        """
        rd = ReDemo()
        rd._test_add()
        """
        data = 'shdkfjh12435hfcjgkv'
        print(re.findall('\d+', data))

    def _test_num(self):
        """
        rd = ReDemo()
        rd._test_num()
        """
        data = "sjdhfksdh123"
        print(re.findall('\d{3}', data))

    def _test_compile(self):
        """
        rd = ReDemo()
        rd._test_compile()
        """
        pattern = re.compile('.+', re.S)
        print(pattern)
        print(pattern.findall("a\nbc"))

    def _test_small_brackets(self):
        """
        rd = ReDemo()
        rd._test_small_brackets()
        """
        print(re.findall(r"a.*bc", "a\nbc", re.DOTALL))
        print(re.findall(r"a(.*b)c", "a\nbc", re.DOTALL))


if __name__ == '__main__':
    rd = ReDemo()
    rd._test_compile()
